package cn.alterzhang.www.test.javabasic;

/**
 * 指令重排测试
 *
 * @author zhangshuhan
 * @date 2019/2/21
 */
public class RearrangInstruct {

    volatile static int x = 0;
    volatile static int y = 0;
    volatile static int a = 0;
    volatile static int b = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread one = new Thread(new Runnable() {
            @Override
            public void run() {
                a = 1;
                x = b;
            }
        });

        Thread other = new Thread(new Runnable() {
            @Override
            public void run() {
                b = 1;
                y = a;
            }
        });
        one.start();
        other.start();
        one.join();
        other.join();
        System.out.println("(" + x + "," + y + ")");
    }

}
